﻿// <copyright file="QldFederalResults2PartyPreferredByElectorate2004FileDefinition.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

using System;
using System.IO;
using FileHelpers;
using FileHelpers.DataLink;

namespace Qut.GenerateKml.Data.FileDefinitions
{
    /// <summary>
    /// Represents the structure of the Qld_Federal Results 2 Party Preferred by Electorate-2004.csv data file.
    /// </summary>
    [DelimitedRecord(","), IgnoreFirst(2)]
    public class QldFederalResults2PartyPreferredByElectorate2004FileDefinition
    {
        /// <summary>
        /// Gets or sets the Division Number
        /// </summary>
        public string DivisionNm { get; set; }

        /// <summary>
        /// Gets or sets the Division ID
        /// </summary>
        public int DivisionID { get; set; }

        /// <summary>
        /// Gets or sets the State Abreviation
        /// </summary>
        public string StateAb { get; set; }

        /// <summary>
        /// Gets or sets the Party Abreviation
        /// </summary>
        public string PartyAb { get; set; }

        /// <summary>
        /// Gets or sets the Liberal National Coalition Votes
        /// </summary>
        public int LiberalNationalCoalitionVotes { get; set; }

        /// <summary>
        /// Gets or sets the Liberal National Coalition Percentage
        /// </summary>
        public double LiberalNationalCoalitionPercentage { get; set; }

        /// <summary>
        /// Gets or sets the Australian Labor Party Votes
        /// </summary>
        public int AustralianLaborPartyVotes { get; set; }

        /// <summary>
        /// Gets or sets the Australia Labor Party Percentage
        /// </summary>
        public double AustralianLaborPartyPercentage { get; set; }

        /// <summary>
        /// Gets or sets the Total Votes
        /// </summary>
        public int TotalVotes { get; set; }

        /// <summary>
        /// Gets or sets the Swing
        /// </summary>
        public double Swing { get; set; }

        /// <summary>
        /// Loads the specified data file from the file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="db">The data context.</param>
        public static void Load(string filePath, SociologicalDataClassesDataContext db)
        {
            var engine = new FileHelperEngine(typeof(QldFederalResults2PartyPreferredByElectorate2004FileDefinition));
            var results = engine.ReadFile(filePath) as QldFederalResults2PartyPreferredByElectorate2004FileDefinition[];
            db.TruncateQldFederalResults2PartyPreferredByElectorate2004();
            foreach (var item in results)
            {
                var record = new QldFederalResults2PartyPreferredByElectorate2004();
                record.AustralianLaborPartyPercentage = item.AustralianLaborPartyPercentage;
                record.AustralianLaborPartyVotes = item.AustralianLaborPartyVotes;
                record.DivisionID = item.DivisionID;
                record.DivisionNm = item.DivisionNm;
                record.ID = record.ID;
                record.LiberalNationalCoalitionPercentage = item.LiberalNationalCoalitionPercentage;
                record.LiberalNationalCoalitionVotes = item.LiberalNationalCoalitionVotes;
                record.PartyAb = item.PartyAb;
                record.StateAb = item.StateAb;
                record.Swing = item.Swing;
                record.TotalVotes = item.TotalVotes;
                db.QldFederalResults2PartyPreferredByElectorate2004s.InsertOnSubmit(record);
            }

            db.SubmitChanges();
        }
    }
}
